using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace Code5Systems.FormMaster.Business
{

	#region Public Enumerations

	public enum ControlType
	{
		None = 0,
		TextBox = 1,
		DropDownList = 2,
		CheckBox = 3,
		CheckBoxList = 4,
		RadioButtonList = 5,
		RequiredFieldValidator = 6,
		RegularExpressionValidator = 7,
		ListBox = 8,
		CompareValidator = 9,
		Label = 10,
		FileUpload = 11,
		SubmitButton = 12,
		HiddenField = 13,
		ChkListValidator = 14,
		HTMLEditor = 15
	}
	
	public enum ButtonType
	{
		None = 0,
		Button = 1,
		LinkButton = 2,
		ImageButton = 3
	}
	
	public enum TemplateType
	{
		XSL = 1,
		Text = 2,
		Custom = 3
	}
	
	public enum DocType
	{
		HTML40 = 0,
		XHTML10 = 1,
		XHTML11 = 2
	}
	
	public enum EmailEncoding
	{
		@Default = 0,
		UTF8 = 1,
		UTF7 = 2,
		Unicode = 3,
		ASCII = 4,
		UTF32 = 5,
		BigEndianUnicode = 6
	}
	
	public enum FormPostResult
	{
		Success = 0,
		FailedEmail = 1,
		FailedRegistration = 2
	}

	public enum JsonDataType
	{
		Json,
		Html
	}

	public enum CaptchaType
	{
		DefaultCaptcha = 0,
		GoogleReCaptcha = 1
	}

	#endregion
	
	internal class Constants
	{
		public const string DECLARATIONS = "Declarations";
		public const string FUNCTIONS = "Functions";
		public const string DOCREADY = "DocReady";
		public const string PAGELOAD = "PageLoad";
		public const string PAGELOADEND = "PageLoadEnd";
		public const string DEFAULT_PAGE = "<Form><Heading></Heading><Controls/></Form>";
		public const string LICENSE_CACHE_KEY = "LicenseCacheKey";
		public const string DECLARATION = "var $cascade_R{0}C{1}P{2};{3}";
		public const string SELECTOR = "$cascade_R{0}C{1}P{2} = jQuery(\"select[id$=\'{3}\']\");{4}";
		public const string PARENT = "$cascade_R{0}C{1}P{2}.data(\"parent\", \"{3}\");{4}";
		public const string SELF = "$cascade_R{0}C{1}P{2}.data(\"self\", \"{3}\");{4}";
		public const string CHILD = "$cascade_R{0}C{1}P{2}.data(\"child\", \"{3}\");{4}";
		public const string GRANDCHILD = "$cascade_R{0}C{1}P{2}.data(\"grandChild\", \"{3}\");{4}";
		public const string PROMPT = "$cascade_R{0}C{1}P{2}.data(\"prompt\", \"{3}\");{4}";
		public const string LOADALLITEMS = "loadItemsRecursive(\'{0}\');{1}";
		public const string ONCHANGE_LINE_1 = "$cascade_R{0}C{1}P{2}.change(function () {3}";
		public const string ONCHANGE_LINE_2 = "\t" + "loadItems($cascade_R{0}C{1}P{2}.data(\"child\"), $cascade_R{0}C{1}P{2}.val());{3}";
		public const string ONCHANGE_LINE_3 = "\t" + "setPrompt($cascade_R{0}C{1}P{2}.data(\"grandChild\"));{3}";
		public const string DISABLED_RULE_VALIDATORS = "DisabledRuleValidators";
		public const string DISABLED__VALIDATORS_ID = "ctl_ceb1ad59b2864732a1e4814ab87a5360";
		public const int DEBUG_SLEEP_SPAN = 1000;
	}
	
	public static class ListExtensions
	{
		public static string ToCsv(this List<string> listOfString)
		{
			StringBuilder csv = new StringBuilder();
			char[] comma = new char[] {','};
			try
			{
				foreach (string item in listOfString)
				{
					csv.Append(item.Trim() + ",");
				}
			}
			catch
			{
			}
			return System.Convert.ToString( (csv.Length == 0 ? string.Empty : (csv.ToString().TrimEnd(comma))).ToString());
		}
		
		public static List<string> FromCSV(this string CSVString, char separator = ',')
		{
			List<string> list = new List<string>();
			try
			{
				list = CSVString.Split(',').Cast<string>().ToList();

				//char[] arySeparater = new char[1];
				//arySeparater[0] = separator;
				
				//foreach (string item in CSVString.Split(arySeparater.ToString().ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
				//{
				//	list.Add(item);
				//}
			}
			catch
			{
			}
			
			return list;
		}
	}
}


